import { getSettingGetdepartmentusers } from "@/api/siderBar/setting";
import type { CascaderProps } from "ant-design-vue";

export function useFetchDepUsers() {
    const { data: depUsers, refreshAsync, loading } = useRequest(() => getSettingGetdepartmentusers(), {
            initialData: []
        })
        const depUserOptions = computed<CascaderProps['options']>(() => {
            if (depUsers.value && depUsers.value.length > 0) {
                return depUsers.value.map(depUser => {
                    return {
                        value: depUser.departmentId,
                        label: depUser.departmentName!,
                        children: depUser.users?.map(user => {
                            return {
                                value: user.userId,
                                label: user.userName!
                            }
                        })
                    }
                })
            }
            return []
        });
    return {
        refreshAsync,
        depUsers,
        depUserOptions,
        loading
    }
}